package com.zj.controller;

import com.zj.pojo.dto.GoodsDTO;
import com.zj.pojo.vo.FinalResultVO;
import com.zj.pojo.vo.GoodsVO;
import com.zj.service.GoodsService;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 赵赳
 * @since 2021/12/22 9:40
 */
@Slf4j
@RestController
public class GoodsController {

  private final GoodsService goodsService;

  public GoodsController(GoodsService goodsService) {
    this.goodsService = goodsService;
  }

  /**
   * 存储数据到ES
   *
   * @param key key
   * @return 执行结果
   */
  @GetMapping("/dataToEs/{key}")
  public boolean dataToEs(@PathVariable(value = "key") String key) throws Exception {
    return goodsService.parseGoodsToEs(key);
  }

  /**
   * 获取es数据
   *
   * @param dto 请求体
   * @return 数据
   */
  @PostMapping("/getGoods")
  public FinalResultVO<Map<String, Object>> getGoods(@RequestBody GoodsDTO dto) {
    return goodsService.getGoods(dto);
  }


}
